package com.example.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.config.ResponseVO;
import com.example.pojo.StuInfo;
import com.example.pojo.dto.StuInfoDTO;
import com.example.service.StuInfoService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@SuppressWarnings("all")
public class StuInfoController {
    @Resource
    private StuInfoService stuInfoService;

    /**
     * 查询所有学生的信息
     * @return 返回的是VO对象，内容是学生信息集合数组
     */
    @GetMapping("/stuInfoList")
    public ResponseVO<List<StuInfo>> stuInfoResponseVO() {
        List<StuInfo> stuInfos = stuInfoService.stuInfoList();
        System.out.println("卧槽！！！！！！！！！！！！！！！！！！！！！！！！");
        return ResponseVO.success(stuInfos);
    }

    //分页查询/查全部
    @GetMapping("/stuInfoListPage/{currentPage}/{limit}")
    public ResponseVO<IPage<StuInfo>> stuInfoListPage(@PathVariable int currentPage,@PathVariable int limit) {
        IPage<StuInfo> stuInfos = stuInfoService.stuInfoListPage(currentPage,limit);
        return ResponseVO.success(stuInfos);
    }


    //多条件查询
    @GetMapping("/getStuByNameAndClassLevels/{currentPage}/{limit}/{name}")
    public ResponseEntity<ResponseVO<IPage<StuInfo>>> getStudentsByNameAndClassLevels(
            @PathVariable int currentPage,
            @PathVariable int limit,
            @PathVariable(required = false) String name,
            @RequestParam(required = false) List<String> classLevels) {


            IPage<StuInfo> stuInfoIPage=stuInfoService.getStuByNameAndClassLevels(currentPage,limit,name,classLevels);
            return  ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"获取成功",stuInfoIPage));
    }




    @GetMapping("/stuInfoDtoById")
    public ResponseVO<StuInfoDTO> stuInfoDTOResponseVO(@RequestParam String stuId) {
        StuInfoDTO stuInfoDTO = stuInfoService.stuInfoDtoByID(Long.parseLong(stuId));
        return ResponseVO.success(stuInfoDTO);
    }

    @PostMapping("/addOrUpdateStuInfo")
    public ResponseEntity<ResponseVO<String>> addStuInfo(@RequestBody StuInfo stuInfo) {
        String result = stuInfoService.addOrUpdateStuInfo(stuInfo);
        return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,result));
    }

    @DeleteMapping("/deleteStuInfo/{stuId}")
    public ResponseVO deleteStuInfo(@PathVariable Long stuId) {
        String result = stuInfoService.deleteStuInfo(stuId);
        return ResponseVO.success(result);
    }
}
